using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.ContactsDomain;
//using ShivamEMR.Web.Areas.Contacts.Models;
using ShivamEMR.Model.DataInterfaces.ContactsDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Contacts.Controllers
{   
    public class AddressTypeController : Controller
    {
		private readonly IAddressTypeRepository addresstypeRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public AddressTypeController() 
        {
            addresstypeRepository = Registry.RepositoryFactory.GetAddressTypeRepository();
        }

        public AddressTypeController(IAddressTypeRepository addresstypeRepository)
        {
			this.addresstypeRepository = addresstypeRepository;
        }

        //
        // GET: /AddressType/

        public ViewResult Index()
        {
        //    return View(addresstypeRepository.AllIncluding(addresstype => addresstype.Addresses));
            return View(addresstypeRepository.All);
        }

        //
        // GET: /AddressType/Details/5

        public ViewResult Details(int id)
        {
            return View(addresstypeRepository.Find(id));
        }

        //
        // GET: /AddressType/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /AddressType/Create

        [HttpPost]
        public ActionResult Create(AddressType addresstype)
        {
            if (ModelState.IsValid) {
                addresstypeRepository.InsertOrUpdate(addresstype);
                addresstypeRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /AddressType/Edit/5
 
        public ActionResult Edit(int id)
        {
             return View(addresstypeRepository.Find(id));
        }

        //
        // POST: /AddressType/Edit/5

        [HttpPost]
        public ActionResult Edit(AddressType addresstype)
        {
            if (ModelState.IsValid) {
                addresstypeRepository.InsertOrUpdate(addresstype);
                addresstypeRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /AddressType/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(addresstypeRepository.Find(id));
        }

        //
        // POST: /AddressType/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var atype = addresstypeRepository.Find(id);
            addresstypeRepository.Delete(atype);
            addresstypeRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

